<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>帮帮网</title>
<link href="../default.css" media="screen" rel="stylesheet" />

<script type="text/javascript" src="../JS/prototype.js"></script>
<script type="text/javascript" src="../JS/httpRequest.js"></script>
<script type="text/javascript" src="../JS/cookie.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>--> 
<script src="../JS/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">  
jQuery.noConflict();

//等待dom元素加载完毕.  
jQuery(document).ready(function(){  
	jQuery("#selector ul li").click(function(){
		if(jQuery(this).hasClass("selector_on"))
		{
			
		}
		else
		{
			var sel_on = jQuery("#selector .selector_on");
			sel_on.addClass("selector_off");
			sel_on.removeClass("selector_on");
			jQuery(this).addClass("selector_on");
			jQuery(this).removeClass("selector_off");
			//todo 刷新任务推送内容
		}
	});

	jQuery("#left_bar ul li").hover(
		function(){
			jQuery(this).addClass("selector_on");
			jQuery(this).removeClass("selector_off");
			//todo 抽出关注度最高的十个人 悬浮于右侧
		},
		function(){
			jQuery(this).addClass("selector_off");
			jQuery(this).removeClass("selector_on");
			//todo 取消显示右侧的人名
		}
	);

});  
</script> 
<script type="text/javascript">
function GetiActivityList()
{
	jQuery("#activities").show();
	jQuery("#addActTable").hide();
	var username=getCookie('username');
	var userID = getCookie('userID');
	if(!userID)
	{
		alert("请先登录");
		return;
	}
	var url="activity.php?action=GetiActivityList";
	var para="userID="+userID;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp!=null)
	{
		//alert('debug');
		var actListDiv=document.getElementById('activities');
		//刷新前 先清空子节点 这边纯粹为鲁棒性了 目前来说没必要
		//但是考虑这个函数假设以后再页面里面被反复调用的话 还是需要先清空子节点的
		var childs = actListDiv.childNodes;
		for(var i=childs.length-1; i>=0; i--){
			actListDiv.removeChild(childs[i]);
		}

		//alert('actListDiv');		
		eval("actList="+resp);		//alert(actList.length);  alert(actList);
		g_timeDivList=new Array(actList.length);
		for(var i=0;i<actList.length;i++)
		{
			var actDiv=document.createElement("div");
			actDiv.setAttribute("class","activity");
			//actDiv.style.width="700px";
			actDiv.style.margin="20px";
			actDiv.style.border="1px solid #ccc";
			
			//标题
			var titleDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			titleDiv.innerHTML="<a href=activityInfo.php?activityId="+actList[i].id+">"+actList[i].title+"</a>";				
			actDiv.appendChild(titleDiv);
	
			//简介
			var descDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			descDiv.innerHTML=actList[i].desc;				
			actDiv.appendChild(descDiv);
			
			//剩余时间
			var timeDiv=document.createElement("div");
			timeDiv.name="timeDiv";
			timeDiv.createTime=actList[i].createTime;
			timeDiv.lastDays=actList[i].lastDays;
			timeDiv.innerHTML="剩余时间："+actList[i].leftTime;	
			g_timeDivList[i]=timeDiv;
			actDiv.appendChild(g_timeDivList[i]);
			
			//已参与人数
			var joinNumDiv=document.createElement("div");
			joinNumDiv.id="joinNum"+actList[i].id;
			joinNumDiv.innerHTML="已有"+actList[i].joinNum+"人参与";
			actDiv.appendChild(joinNumDiv);
			
			
			//加入活动按钮
			//alert('id');			alert(actList[i].id);
			var btnDiv=document.createElement("div");
			btnDiv.style.textAlign="right";
			btnDiv.innerHTML="<input actId='"+actList[i].id+"' type='button' style='border:1px solid #ccc' value='加入活动' onclick='JoinActivity(this)'/>";
			actDiv.appendChild(btnDiv);
			

			
			actListDiv.appendChild(actDiv);				
		}
		
		
		//定时刷新活动的剩余时间
		setInterval("FlashLeftTime()",1000);
		//FlashLeftTime();
	}
}

function GetfActivityList()
{
	jQuery("#activities").show();
	jQuery("#addActTable").hide();

	var username=getCookie('username');
	var userID = getCookie('userID');
	if(!userID)
	{
		alert("请先登录");
		return;
	}
	var url="activity.php?action=GetfActivityList";
	var para="userID="+userID;
	var resp=SendPostRequest(url,para);
	alert(resp);
	if(resp!=null)
	{
		//alert('debug');
		var actListDiv=document.getElementById('activities');
		//刷新前 先清空子节点 这边纯粹为鲁棒性了 目前来说没必要
		//但是考虑这个函数假设以后再页面里面被反复调用的话 还是需要先清空子节点的
		var childs = actListDiv.childNodes;
		for(var i=childs.length-1; i>=0; i--){
			actListDiv.removeChild(childs[i]);
		}

		//alert('actListDiv');		
		eval("actList="+resp);		//alert(actList.length);  alert(actList);
		g_timeDivList=new Array(actList.length);
		for(var i=0;i<actList.length;i++)
		{
			var actDiv=document.createElement("div");
			actDiv.setAttribute("class","activity");
			//actDiv.style.width="700px";
			actDiv.style.margin="20px";
			actDiv.style.border="1px solid #ccc";
			
			//标题
			var titleDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			titleDiv.innerHTML="<a href=activityInfo.php?activityId="+actList[i].id+">"+actList[i].title+"</a>";				
			actDiv.appendChild(titleDiv);
	
			//简介
			var descDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			descDiv.innerHTML=actList[i].desc;				
			actDiv.appendChild(descDiv);
			
			//剩余时间
			var timeDiv=document.createElement("div");
			timeDiv.name="timeDiv";
			timeDiv.createTime=actList[i].createTime;
			timeDiv.lastDays=actList[i].lastDays;
			timeDiv.innerHTML="剩余时间："+actList[i].leftTime;	
			g_timeDivList[i]=timeDiv;
			actDiv.appendChild(g_timeDivList[i]);
			
			//已参与人数
			var joinNumDiv=document.createElement("div");
			joinNumDiv.id="joinNum"+actList[i].id;
			joinNumDiv.innerHTML="已有"+actList[i].joinNum+"人参与";
			actDiv.appendChild(joinNumDiv);
			
			
			//加入活动按钮
			//alert('id');			alert(actList[i].id);
			var btnDiv=document.createElement("div");
			btnDiv.style.textAlign="right";
			btnDiv.innerHTML="<input actId='"+actList[i].id+"' type='button' style='border:1px solid #ccc' value='加入活动' onclick='JoinActivity(this)'/>";
			actDiv.appendChild(btnDiv);
			

			
			actListDiv.appendChild(actDiv);				
		}
		
		
		//定时刷新活动的剩余时间
		setInterval("FlashLeftTime()",1000);
		//FlashLeftTime();
	}
}

function GetActivityList()
{
	jQuery("#activities").show();
	jQuery("#addActTable").hide();

	var url="activity.php?action=GetActivityList";
	var para=null;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp!=null)
	{
		//alert('debug');
		var actListDiv=document.getElementById('activities');
		//刷新前 先清空子节点 这边纯粹为鲁棒性了 目前来说没必要
		//但是考虑这个函数假设以后再页面里面被反复调用的话 还是需要先清空子节点的
		var childs = actListDiv.childNodes;
		for(var i=childs.length-1; i>=0; i--){
			actListDiv.removeChild(childs[i]);
		}

		//alert('actListDiv');		
		eval("actList="+resp);		//alert(actList.length);  alert(actList);
		g_timeDivList=new Array(actList.length);
		for(var i=0;i<actList.length;i++)
		{
			var actDiv=document.createElement("div");
			actDiv.setAttribute("class","activity");
			//actDiv.style.width="700px";
			actDiv.style.margin="20px";
			actDiv.style.border="1px solid #ccc";
			
			//标题
			var titleDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			titleDiv.innerHTML="<a href=activityInfo.php?activityId="+actList[i].id+">"+actList[i].title+"</a>";				
			actDiv.appendChild(titleDiv);
	
			//简介
			var descDiv=document.createElement('div');
			//titleDiv.style.padding="10px";
			descDiv.innerHTML=actList[i].desc;				
			actDiv.appendChild(descDiv);
			
			//剩余时间
			var timeDiv=document.createElement("div");
			timeDiv.name="timeDiv";
			timeDiv.createTime=actList[i].createTime;
			timeDiv.lastDays=actList[i].lastDays;
			timeDiv.innerHTML="剩余时间："+actList[i].leftTime;	
			g_timeDivList[i]=timeDiv;
			actDiv.appendChild(g_timeDivList[i]);
			
			//已参与人数
			var joinNumDiv=document.createElement("div");
			joinNumDiv.id="joinNum"+actList[i].id;
			joinNumDiv.innerHTML="已有"+actList[i].joinNum+"人参与";
			actDiv.appendChild(joinNumDiv);
			
			
			//加入活动按钮
			//alert('id');			alert(actList[i].id);
			var btnDiv=document.createElement("div");
			btnDiv.style.textAlign="right";
			btnDiv.innerHTML="<input actId='"+actList[i].id+"' type='button' style='border:1px solid #ccc' value='加入活动' onclick='JoinActivity(this)'/>";
			actDiv.appendChild(btnDiv);
			

			
			actListDiv.appendChild(actDiv);				
		}
		
		
		//定时刷新活动的剩余时间
		setInterval("FlashLeftTime()",1000);
		//FlashLeftTime();
	}
}


function JoinActivity(obj)
{
	//这个 session的使用 今后再考虑 通过cookie先取得用户的id
	//alert("joinAct");
	var userID=getCookie("userID");
	var username=getCookie("username");
	//alert(userID);
	if(username==""||username==null)
	{
		var loginDiv=document.getElementById('loginDiv');
		loginDiv.style.display="block";
		loginDiv.style.left=event.clientX+40;
		loginDiv.style.top=event.clientY-40;
		return;
	}
    //alert(username);
	var url="activity.php?action=JoinActivity";
	var para="activityId="+obj.getAttribute("actId");
	//kakassi add 我承认 用cookie而不用session是个败笔 不过先将就好了
	para+="&userID="+userID;//kakassi add
	para+="&username="+username;//kakassi add
	var resp=SendPostRequest(url,para);
	//alert(resp);
	//用户未登录
	if(resp=="NotLogin")
	{
		var loginDiv=document.getElementById('loginDiv');
		loginDiv.style.display="block";
		loginDiv.style.left=event.clientX+40;
		loginDiv.style.top=event.clientY-40;			
	}
	//用户已登录
	else
	{	
	   alert(resp);
	   GetJoinNum(obj.getAttribute("actId"));
	   
	}
}

//根据活动id，获取已参加活动的人数
function GetJoinNum(actId)
{
	//alert('in get join num');
	//alert(actId);
	var url="activity.php?action=GetJoinNum";
	var para="activityId="+actId;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	var joinNumDiv=document.getElementById("joinNum"+actId);	
    joinNumDiv.innerHTML="已有"+resp+"人参与";
}


//刷新剩余时间
function FlashLeftTime()
{
	var url="activity.php?action=GetLeftTime";
	var para=null;
	var resp=SendPostRequest(url,para);
	for(var i=0;i<g_timeDivList.length;i++)
	{
		var para="createTime="+g_timeDivList[i].createTime;
		para+="&lastDays="+g_timeDivList[i].lastDays;
		//alert("i="+i+";"+timeDiv);
		//alert(timeDivList[i].createTime+";"+timeDivList[i].lastDays);
		var resp=SendPostRequest(url,para);
		
		
		g_timeDivList[i].innerHTML="剩余时间:"+resp;		
	}

}

//用户登录
function Login()
{
	alert('login');
	
	if(UserLogin('../user/user.php')!="false")
	{			
		alert('fucks');
		loginDiv.style.display="none";
	}
	
}

//用户退出
function Logout()
{
	UserLogout('../user/user.php');
}

function GetExpiredActivityList()
{
	jQuery("#activities").show();
	jQuery("#addActTable").hide();

	var url="activity.php?action=GetExpiredActivityList";
	var para=null;
	var resp=SendPostRequest(url,para);
	//alert(resp);
	if(resp!=null)
	{
		//alert('debug');
		var actListDiv=document.getElementById('activities');	
		//刷新前 先清空子节点
		var childs = actListDiv.childNodes;
		for(var i=childs.length-1; i>=0; i--){
			actListDiv.removeChild(childs[i]);
		}

		eval("actList="+resp);		//alert(actList.length);  alert(actList);
		g_timeDivList=new Array(actList.length);
		for(var i=0;i<actList.length;i++)
		{
			//var actDiv=document.createElement('div');
			//actDiv.style.width="700px";
			//actDiv.style.margin="20px";
			//actDiv.style.border="1px solid #ccc";
			var actDiv=document.createElement("div");
			actDiv.setAttribute("class","activity");
			//actDiv.style.width="700px";
			actDiv.style.margin="20px";
			actDiv.style.border="1px solid #ccc";			

			//标题
			var titleDiv=document.createElement('div');
			titleDiv.style.padding="10px";
			titleDiv.innerHTML="<a href=activityInfo.php?activityId="+actList[i].id+">"+actList[i].title+"</a>";		
			actDiv.appendChild(titleDiv);
			//简介
			var descDiv=document.createElement('div');
			descDiv.style.padding="10px";
			descDiv.innerHTML=actList[i].desc;		
			actDiv.appendChild(descDiv);					
			//已参与人数
			var joinNumDiv=document.createElement("div");
			joinNumDiv.id="joinNum"+actList[i].id;
			joinNumDiv.style.padding="10px";
			joinNumDiv.innerHTML="有"+actList[i].joinNum+"人参与";
			actDiv.appendChild(joinNumDiv);
			
			actListDiv.appendChild(actDiv);				
		}
		
		
		//定时刷新活动的剩余时间
		setInterval("FlashLeftTime()",1000);
		//FlashLeftTime();
	}
}

function addAct()
{
	jQuery("#activities").hide();
	jQuery("#addActTable").show();
}

function AddActivity()
{
	var userID=getCookie("userID");
	if(CheckEmpty($('txtTitle'),'warnTitle','活动标题不能为空！')&&
		CheckEmpty($('txtLastDays'),'warnLastDays','活动有效期不能为空！')	&&
		CheckEmpty($('txtMaxNum'),'warnMaxNum','活动最多参加人数不能为空！') && 
		CheckEmpty($('txtDetail'),'warnDetail','活动详细信息不能为空！'))
	{
		var url="activity.php?action=AddActivity";
		
		var para="title="+$('txtTitle').value;
		para+="&lastDays="+$('txtLastDays').value;
		para+="&maxNum="+$('txtMaxNum').value;
		para+="&desc="+$('txtDesc').value;
		para+="&detailInfo="+$('txtDetail').value;
		para+="&userID="+userID;	
		//para+="&pic="+$('pic').value;	
		var response=SendPostRequest(url,para);
		alert(response);
		if(response=="true")
		{
			window.location.href="activity.html";
			//var txtAlbumId=document.getElementById('txtAlbumId');//AlbumId
			//var txtAlbumList=document.getElementById('txtAlbumList');
			//alert(txtAlbumList.value);
			//txtAlbumId.value=txtAlbumList.value;//把form表单的txtAlbumId值 用 txtAlbumList 的当前值来赋值
		
			//var uploadForm=document.getElementById('uploadForm');//照片txtPhoto连同txtAlbumId 一起上传 由upload_photo.php接
			//uploadForm.submit();

		}
	}
}
function CheckEmpty(obj,warnID,warnInfo)
{
	var warnElement=document.getElementById(warnID);
	
	if(obj.value==null || obj.value=="")
	{		
		warnElement.innerText=warnInfo;
		return false;
	}
	else
	{
		warnElement.innerText="OK";
	   return true;
	}
}

</script>

</head>
<body onload="GetActivityList()">
  <div id="all">
    <div id="header">
        <div id="inner_header" class="central_fixed_width">
			<img src='../imgpick/uploads/logo.jpg'/> 
		    <h1 class="logo">帮帮网</h1>
            <div id="user_status"><a href="../login.htm">登陆</a>||<a href="../register.html">注册</a></div>
            <ul id="nav_bar">
                <li><a href="#"><span class="nav_item">活动</span></a></li>
                <li><a href="../index.html"><span class="nav_item">悬赏求助大厅</span></a></li>
                <li><a href="../myspace.html"><span class="nav_item">个人主页</span></a></li>
                <li><a href="#"><span class="nav_item">点评</span></a></li>
                <li><a href="#"><span class="nav_item">小说</span></a></li>
                <li class="clear"></li>
            </ul>
        </div>
    </div>
    
    <div id="content" class="central_fixed_width">

        <div class="content_parent">
            <div class="act_column">
                <div id="selector">
                    <ul>
                        <li class="selector_on" onclick="GetActivityList()">当前活动</li>
                        <li class="selector_off" onclick="GetExpiredActivityList()">历史活动</li>
                        <li class="selector_off" onclick="GetiActivityList()">我参与的活动</li>
                        <li class="selector_off" onclick="GetfActivityList()">我朋友参与的活动</li>
                        <li class="selector_off" onclick="addAct()">发布活动</li>
                    </ul>
                    <div class="clear"></div>
                </div>
                <div id="activities">
                </div>

				<div id="addActTable" >
					<table   width="800" cellspacing="20" cellpadding="20">
					<tr>
						<td width="200">活动标题：</td>
						<td ><input type="text"  cols="80" rows="1" id="txtTitle" onblur="CheckEmpty(this,'warnTitle','活动标题不能为空！')" /></td>
						<td id="warnTitle" class="warning">&nbsp;*</td>
					</tr>
					<tr>
						<td>活动有效期：</td>
						<td><input id="txtLastDays" type="text" value="7"  onblur="CheckEmpty(this,'warnLastDays','活动有效期不能为空！')"/>天</td>
						<td id="warnLastDays" class="warning">&nbsp;*</td>
					</tr>
					<tr>
						<td>最多参加人数：</td>
						<td><input id="txtMaxNum" type="text" value="100"  onblur="CheckEmpty(this,'warnMaxNum','活动最多参加人数不能为空！')"/>
						人</td>
						<td id="warnMaxNum" class="warning">&nbsp;*</td>
					</tr>
					<tr>
						<td>活动说明：</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td colspan="2"><textarea id="txtDesc" rows="5" cols="80"></textarea></td>
						<td id="warnDesc" >&nbsp;</td>
					</tr>
					<tr>
						<td>活动详细描述：</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td colspan="2"><textarea id="txtDetail" rows="15" cols="80" onblur="CheckEmpty(this,'warnDetail','活动详细信息不能为空！')"></textarea></td>
						<td id="warnDetail" class="warning">&nbsp;*</td>
					</tr>

					<tr>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td colspan="2" align="center"><input type="button" value="发布活动" onclick="AddActivity()" /></td>
						<td>&nbsp;</td>
					</tr>
					</table>
				</div>


            </div>
        </div>           
    </div>
    
    <div id="footer">
        <div id="inner_footer" class="central_fixed_width">


            <div class="footer_links">
                &copy; 2011 帮帮网 All rights reserved.
            </div>
            <div class="clear"></div>
            
        </div>
    </div>
  </div>
</body>
</html>

